package basic;

import java.util.Objects;
import java.util.Scanner;

import org.junit.Test;

public class StatementTest {
	// 分支
	@Test
	public void iftest() {
		String name = "root";
		String pwd = "123";
		Scanner scan = new Scanner(System.in);
		// boolean表达式
		if (name.equals(scan.next())) {
			if (pwd.equals(scan.next())){
				System.out.println("login ok.");
			}else {
				System.out.println("password error.");
			}
		} else {
			System.out.println("has not this user.");
		}
	}
	
	@Test
	public void switchTest() {
		// 6值:byte,short,char,int,String,enum
		String color = "red222";
		switch (color) {
		case "red": System.out.println("红灯"); break;
		case "yellow": System.out.println("黄灯"); break ;
		case "green": System.out.println("g"); break;
		default: System.out.println("other");
		}
	}
	
	// 循环 乘法运算
	@Test
	public void forTest() {
		int[] arr = {1,2,3,4,5};
		for(int i = 0 ; i < arr.length; i++) {
			int j = arr[i];
			System.out.println(j);
		}
		System.out.println("----------------");
		
		// 标签: 循环体
		// break 标签;   退出多层循环
		label:
		for (int i = 0; i < 9; i++) {
			System.out.println("i=" + i);
			for (int j = 0; j < 9; j++) {
				System.out.print("\tj=" + j);
				break label;
			}
			System.out.println();
		}
	}
	
	@Test
	public void forEachTest() {
		int[] arr = {1,2,3,4,5};
		// jdk1.5以后新增，提升遍历效率
		for(int i : arr) {
			System.out.println(i);
		}
	}
	
	@Test
	public void whileTest() {
		int i = 0;
		// boolean表达式
		while(i < 10) {
			System.out.println(i);
			i++;
		}
	}
	
	@Test
	public void doWhileTest() {
		int i = 0;
		do {
			System.out.println(i);
			i++;
		}while(i < 10);
	}
}
